#!/home/hadoop/python26/bin/python
import json
import sys
import mylib

for line in sys.stdin:
    r = None
    try:
        w = line.strip().split('\t')
        r = json.loads(w[-1])
    except:
        continue
    if r != None:
        new_text, sig = mylib.Twitter.detect_rt(r)
        if new_text !='' and sig != '':
            new_r = {}
            new_r['id'] = r['id']
            new_r['raw_text'] = r['text']
            new_r['new_text'] = new_text
            new_r['md5'] = sig
            new_r['user_id'] = r['user']['id']
            new_r['table_id'] = 'neighbor'
            new_r['date'] = r['date']
            new_str = json.dumps(new_r, sort_keys = False)
            print new_str
